﻿using System;
using System.Collections.Generic;
using System.Text;
using Castle.Services.Transaction;
using MiragePWF.NH.Logging;
using MiragePWF.NH.Repositories;
using NHibernate.Criterion;
using Wolfut.MirageEE.Domain.Products;
using Wolfut.MirageEE.Domain.CommonUtilities;
using Wolfut.MirageEE.Interface.Products;

namespace Wolfut.MirageEE.Server.Server.Products
{
    [Transactional]
    [AutoLogging]
    public class WarehousesService : IWarehousesService
    {
        private static object lockObj = new object();
        private readonly IRepository<Warehouse> warehouseRepository;
        public WarehousesService(IRepository<Warehouse> warehouseRepository)
        {
            this.warehouseRepository = warehouseRepository;
        }
        public Warehouse AddOrUpdateWarehouse(Warehouse item)
        {
            this.warehouseRepository.Save(item);
            return item;
        }
        public IList<Warehouse> listWarehouse(Boolean isDeleted)
        {
            DetachedCriteria criteria = DetachedCriteria.For(typeof(Warehouse));           
            criteria.Add(Expression.Eq("IsDeleted", isDeleted));
            criteria.AddOrder(new Order("WarehouseCode", false));
            return warehouseRepository.FindAll(criteria);
        }
    }
}
